//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CCompositeTexture.h>
///	@path	~/src/gui/composite/
///	@date	2008/09/09
///	@brief	.

#pragma once

#include "xeres.h"

#include "graphics/dx9/CDevice9.h"

#include "graphics/DxMath.h"
#include "graphics/ITexture.h"

#include "gui/composite/layer.h"

namespace xeres {

	/*! 
		\class	CCompositeTexture
		\brief
	*/
	class CCompositeTexture : public ITexture
	{
	public:

		/// \ctor
		CCompositeTexture( void );

		/// \dtor
		virtual ~CCompositeTexture( void );

		DECL_IOBJECT_CLASS( CCompositeTexture , ITexture );

	public:

		/// \name ITexture Interface
		//@{

		/// \impl
		virtual TextureType GetType( void );

		/// \impl
		virtual DXFormat GetFormat( void );

		/// \impl
		virtual Pair<int> GetSize( void );

		/// \impl
		virtual size_t GetDepth( void );

		/// \impl
		virtual bool IsWritable( void );

		/// \impl
		virtual bool IsReadable( void );

		/// \impl
		virtual bool Map( uint sub , ResourceMap& data );

		/// \impl
		virtual bool ReadBack( uint sub , ResourceMap& data , bool readonly );

		/// \impl
		virtual bool Unmap( uint sub );

		/// \impl
		virtual bool Update( uint sub , const Box<uint>& size , const byte * data , uint row_pitch , uint depth_pitch );

		/// \impl
		virtual IUnknown * GetTextureInterface( void );

		/// \impl
		virtual bool OnLostDevice( void );

		/// \impl
		virtual bool OnResetDevice( RefWeak<IDevice> device );

		//@}

		/*!
			\brief		Reset canvas element.
		*/
		bool Reset( RefWeak<IRenderer> renderer , const Pair<int>& size , bool update );

		/*!
			\brief		Update canvas content to texture.
		*/
		void Update( const Rect<int>& region );

		/*!
			\brief		Get layer of canvas.
		*/
		Layer& GetLayer( void ) { return m_layer; }

		/*! 
			\brief		Attached texture.
		*/
		bool IsAttached( void ) { return m_texture.IsValid(); }

		// save
		void Save( void );

	private:

		//@ data

		// real texture
		Ref<ITexture>		m_texture;

		// color order for texture
		enum ColorOrder		m_color;

		// composite layer
		Layer				m_layer;
	};

} // namespace xeres
